package com.wang.blog.service.impl;

import com.wang.blog.dao.MeCategoryDAO;
import com.wang.blog.model.MeCategory;
import com.wang.blog.model.MeCategoryExample;
import com.wang.blog.ov.CategoryVO;
import com.wang.blog.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/**
 * @author 王益波
 * @version 1.0
 * @date 2020/9/13 20:59
 */
@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    MeCategoryDAO meCategoryDAO;
    @Override
    public List<MeCategory> findAll() {
        MeCategoryExample meCategoryExample=new MeCategoryExample();
        MeCategoryExample.Criteria criteria=meCategoryExample.createCriteria();
        return meCategoryDAO.selectByExample(meCategoryExample);
    }

    @Override
    public MeCategory getCategoryById(Integer id) {
        return null;
    }

    @Override
    public Integer saveCategory(MeCategory category) {
        return null;
    }

    @Override
    public Integer updateCategory(MeCategory category) {
        return null;
    }

    @Override
    public void deleteCategoryById(Integer id) {

    }

    @Override
    public List<CategoryVO> findAllDetail() {
        List<CategoryVO> list=new ArrayList<>();
        List<MeCategory> listmeCategory=meCategoryDAO.selectByExample(new MeCategoryExample());

        for (MeCategory meCategory:listmeCategory
             ) {
            CategoryVO categoryVO=new CategoryVO();


            categoryVO.setAvatar(meCategory.getAvatar());
            categoryVO.setCategoryname(meCategory.getCategoryname());
            categoryVO.setDescription(meCategory.getDescription());
            categoryVO.setId(meCategory.getId());
            categoryVO.setArticles(meCategoryDAO.listArtclesByCategory(meCategory.getId()));

            list.add(categoryVO);
        }
        return list;
    }

    @Override
    public CategoryVO getCategoryDetail(Integer categoryId) {
        CategoryVO categoryVO=new CategoryVO();
        MeCategory meCategory=meCategoryDAO.selectByPrimaryKey(categoryId);

        categoryVO.setAvatar(meCategory.getAvatar());
        categoryVO.setCategoryname(meCategory.getCategoryname());
        categoryVO.setDescription(meCategory.getDescription());
        categoryVO.setId(categoryId);

        categoryVO.setArticles(meCategoryDAO.listArtclesByCategory(categoryId));
        return categoryVO;
    }
}
